/**
 * 
 */
package org.easyframework.activemq;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.core.MessagePostProcessor;
import org.springframework.stereotype.Component;

/**
 * 
 * @ClassName: QueueSender   
 * @Description: activemq队列消息发送类
 * @author: daiw
 * @date: 2019年10月15日 下午4:37:18
 */
@Component
public class EasyMqSender {
	@Autowired
	private JmsTemplate jmsTemplate;// 通过@Qualifier修饰符来注入对应的bean

	public void send(String queueName, String message) {
		jmsTemplate.send(queueName, new MessageCreator() {
			@Override
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(message);
			}
		});
	}

	public <T extends MessagePostProcessor> void sendDelayMessage(String queueName, String message, T processor) {
		jmsTemplate.convertAndSend(queueName, message, processor);
	}

}
